import { useEffect } from 'react';

import {
  ArticleModelState,
  useDispatch,
  useSelector,
} from 'umi';

import styles from './index.less';

export default function IndexPage() {
  const dispatch = useDispatch();
  //获取数据
  const { articleList } = useSelector((state: { article: ArticleModelState }) => state.article)
  //渲染
  useEffect(() => {
    //发起请求
    dispatch({
      //类型  命名空间下的/请求数据函数
      type: "article/getArticleList",
    })
  }, [])

  return (
    <div>
      <h1 className={styles.title}>Page index</h1>
      {
        articleList.map((item: any) => {
            return <div key={item.id}>
               <p>{item.title}</p>
               <img src={item.cover} alt="" />
            </div>
        })
      }
    </div>
  );
}
